﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ruoxian_novel
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            //加载窗体
            this.Width = 480;
            this.Height = 330;
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_wangjimima.Enabled = false;
            panel_xiugaimima.Enabled = false;
            panel_zhucezhanghao.Enabled = false;
            panel_zhucexinxi.Enabled = false;
            panel_shurumima.Enabled = false;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_wangjimima_email.TabStop = false;
            textBox_wangjimima_yanzhengma.TabStop = false;
            textBox_xiugaimima_xinmima.TabStop = false;
            textBox_xiugaimima_querenmima.TabStop = false;
            textBox_zhucezhanghao_email.TabStop = false;
            textBox_zhucezhanghao_yanzhengma.TabStop = false;
            textBox_zhucexinxi_name.TabStop = false;
            comboBox_zhucexinxi_xingbie.TabStop = false;
            comboBox_zhucexinxi_shengri_nian.TabStop = false;
            comboBox_zhucexinxi_shengri_yue.TabStop = false;
            comboBox_zhucexinxi_diqu.TabStop = false;
            textBox_shurumima_mima.TabStop = false;
            textBox_shurumima_querenmima.TabStop = false;
        }

        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //关闭窗体 退出程序
            //是否退出程序
            if (Exit.exit)
            {
                Application.Exit();
            }
        }

        private void button_denglu_Click(object sender, EventArgs e)
        {
            if (textBox_zhanghao.Text == "")//未输入账号时
            {
                button_denglushibai.Text = "您还没有输入账号呢！";
                this.Height = 390;
                button_denglushibai.Left = 22;
            }
            else if (textBox_mima.Text == "")//未输入密码时
            {
                button_denglushibai.Text = "您还没有输入密码呢！";
                this.Height = 390;
                button_denglushibai.Left = 22;
            }
            else
            {
                try
                {
                    //登录按钮 查询数据
                    string sql = string.Format("select y.Zhanghao,y.Mima,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Zhanghao='{0}'", textBox_zhanghao.Text);
                    DataTable dt = DBHelper.GetDataTable(sql);
                    //登录按钮 匹配数据
                    if (textBox_mima.Text == dt.Rows[0][1].ToString())
                    {
                        //登录按钮 成功登录 备份用户数据
                        Yonghu.mima = textBox_mima.Text;
                        Yonghu.zhanghao = dt.Rows[0][0].ToString();
                        Yonghu.shenfen = dt.Rows[0][2].ToString();
                        Yonghu.name = dt.Rows[0][3].ToString();
                        Yonghu.xingbie = dt.Rows[0][4].ToString();
                        Yonghu.shengri = dt.Rows[0][5].ToString().Substring(0, dt.Rows[0][5].ToString().IndexOf(' '));
                        Yonghu.diqu = dt.Rows[0][6].ToString();
                        Yonghu.jianjie = dt.Rows[0][7].ToString();
                        Yonghu.email = dt.Rows[0][8].ToString();
                        //登录按钮 成功登录 离开登录窗体
                        Exit.exit = false;
                        this.Close();
                    }
                    else
                    {
                        //登录按钮 登录失败 密码错误
                        button_denglushibai.Text = "您输入了错误的密码或账号。请检查您的密码和账号并重试。";
                        this.Height = 390;
                        button_denglushibai.Left = 22;
                    }
                }
                catch
                {
                    //登录按钮 登录失败 此账号不存在
                    button_denglushibai.Text = "您输入了不存在的账号。请检查您的账号并重试。";
                    this.Height = 390;
                    button_denglushibai.Left = 22;
                }
            }
        }

        private void textBox_zhanghao_KeyPress(object sender, KeyPressEventArgs e)
        {
            //账号输入
            if (e.KeyChar != '\b')//允许输入退格
            {
                if (e.KeyChar < '0' || e.KeyChar > '9')//允许输入数字
                {
                    e.Handled = true;
                }
            }
        }

        private void button_quxiao_Click(object sender, EventArgs e)
        {
            //取消按钮 退出程序
            Application.Exit();
        }

        private void button_denglu_MouseEnter(object sender, EventArgs e)
        {
            //登录按钮 鼠标悬停时颜色
            button_denglu.ForeColor = Color.White;
        }

        private void button_denglu_MouseLeave(object sender, EventArgs e)
        {
            //登录按钮 鼠标离开时颜色
            button_denglu.ForeColor = Color.Black;
        }

        private void button_denglu_MouseDown(object sender, MouseEventArgs e)
        {
            //登录按钮 鼠标单击时颜色
            button_denglu.ForeColor = Color.Black;
        }

        private void button_wangjimima_Click(object sender, EventArgs e)
        {
            //忘记密码
            button_denglushibai.Left = 500;
            this.Width = 480;
            this.Height = 330;
            this.Text = "若闲Ruoxian-Novel    忘记密码";
            panel_wangjimima.Left = 12;
            panel_wangjimima.Top = 12;
            panel_wangjimima.BringToFront();
            panel_wangjimima.Enabled = true;
            textBox_zhanghao.Enabled = false;
            textBox_mima.Enabled = false;
            checkBox_jizhumima.Enabled = false;
            button_wangjimima.Enabled = false;
            button_zhucezhanghao.Enabled = false;
            textBox_wangjimima_email.TabStop = true;
            textBox_wangjimima_yanzhengma.TabStop = true;
            textBox_zhanghao.TabStop = false;
            textBox_mima.TabStop = false;
        }

        private void button_wangjimima_quxiao_Click(object sender, EventArgs e)
        {
            //忘记密码 取消
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_wangjimima.Left = 492;
            panel_wangjimima.Top = 12;
            panel_wangjimima.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_wangjimima_email.TabStop = false;
            textBox_wangjimima_yanzhengma.TabStop = false;
            textBox_wangjimima_email.Text = "";
            textBox_wangjimima_yanzhengma.Text = "";
        }

        private void button_huoquyanzhengma_Click(object sender, EventArgs e)
        {
            //忘记密码 获取验证码
            if (textBox_wangjimima_email.Text == "")
            {
                MessageBox.Show("您还未输入电子邮箱地址！");
            }
            string sql = string.Format("select count(*) from Yonghu where Email='{0}'", textBox_wangjimima_email.Text);
            DataTable dt = DBHelper.GetDataTable(sql);
            if (dt.Rows[0][0].ToString() == "0")
            {
                MessageBox.Show("此邮箱还未注册账号！");
            }
            else
            {
                Yanzhengma.yanzhengma = Email.email(textBox_wangjimima_email.Text);
            }
        }

        private void button_wangjimima_queding_Click(object sender, EventArgs e)
        {
            //忘记密码 确定
            if (textBox_wangjimima_email.Text == "")
            {
                MessageBox.Show("您还未输入电子邮箱地址！");
                return;
            }else if (textBox_wangjimima_yanzhengma.Text == "")
            {
                MessageBox.Show("您还未输入验证码！");
                return;
            }
            string sql = string.Format("select count(*) from Yonghu where Email='{0}'", textBox_wangjimima_email.Text);
            DataTable dt = DBHelper.GetDataTable(sql);
            if (dt.Rows[0][0].ToString() == "0")
            {
                MessageBox.Show("此邮箱还未注册账号！");
                return;
            }
            else if (dt.Rows[0][0].ToString() == "1")
            {
                if (textBox_wangjimima_yanzhengma.Text == Yanzhengma.yanzhengma)
                {
                    //忘记密码 查询数据
                    sql = string.Format("select y.Zhanghao,y.Mima,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Email='{0}'", textBox_wangjimima_email.Text);
                    dt = DBHelper.GetDataTable(sql);
                    //忘记密码 备份用户数据
                    Yonghu.zhanghao = dt.Rows[0][0].ToString();
                    Yonghu.mima = dt.Rows[0][1].ToString();
                    Yonghu.shenfen = dt.Rows[0][2].ToString();
                    Yonghu.name = dt.Rows[0][3].ToString();
                    Yonghu.xingbie = dt.Rows[0][4].ToString();
                    Yonghu.shengri = dt.Rows[0][5].ToString();
                    Yonghu.diqu = dt.Rows[0][6].ToString();
                    Yonghu.jianjie = dt.Rows[0][7].ToString();
                    Yonghu.email = dt.Rows[0][8].ToString();
                    //打开修改密码页面
                    panel_xiugaimima.Left = 12;
                    panel_xiugaimima.Top = 12;
                    panel_xiugaimima.BringToFront();
                    panel_xiugaimima.Enabled = true;
                    panel_wangjimima.Enabled = false;
                    textBox_xiugaimima_xinmima.TabStop = true;
                    textBox_xiugaimima_querenmima.TabStop = true;
                    textBox_wangjimima_email.TabStop = false;
                    textBox_wangjimima_yanzhengma.TabStop = false;
                }
                else
                {
                    MessageBox.Show("您输入了不正确的验证码！");
                }
            }
            else
            {
                MessageBox.Show("多个账号绑定该邮箱，请联系管理员！");
            }
        }

        private void button_zhucezhanghao_Click(object sender, EventArgs e)
        {
            //注册账号
            button_denglushibai.Left = 500;
            this.Width = 480;
            this.Height = 330;
            this.Text = "若闲Ruoxian-Novel    注册账号";
            panel_zhucezhanghao.Left = 12;
            panel_zhucezhanghao.Top = 12;
            panel_zhucezhanghao.BringToFront();
            panel_zhucezhanghao.Enabled = true;
            textBox_zhanghao.Enabled = false;
            textBox_mima.Enabled = false;
            checkBox_jizhumima.Enabled = false;
            button_wangjimima.Enabled = false;
            button_zhucezhanghao.Enabled = false;
            textBox_zhucezhanghao_email.TabStop = true;
            textBox_zhucezhanghao_yanzhengma.TabStop = true;
            textBox_zhanghao.TabStop = false;
            textBox_mima.TabStop = false;
        }

        private void button_zhucezhanghao_quxiao_Click(object sender, EventArgs e)
        {
            //注册账号 取消
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_zhucezhanghao.Left = 492;
            panel_zhucezhanghao.Top = 12;
            panel_zhucezhanghao.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_zhucezhanghao_email.TabStop = false;
            textBox_zhucezhanghao_yanzhengma.TabStop = false;
            textBox_zhucezhanghao_email.Text = "";
            textBox_zhucezhanghao_yanzhengma.Text = "";
        }

        private void button_xiugaimima_quxiao_Click(object sender, EventArgs e)
        {
            //修改密码 取消
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_xiugaimima.Left = 492;
            panel_xiugaimima.Top = 12;
            panel_wangjimima.Left = 492;
            panel_wangjimima.Top = 12;
            panel_xiugaimima.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_xiugaimima_xinmima.TabStop = false;
            textBox_xiugaimima_querenmima.TabStop = false;
            textBox_wangjimima_email.Text = "";
            textBox_wangjimima_yanzhengma.Text = "";
            textBox_xiugaimima_xinmima.Text = "";
            textBox_xiugaimima_querenmima.Text = "";
        }

        private void button_xiugaimima_queding_Click(object sender, EventArgs e)
        {
            //修改密码 确定
            if (textBox_xiugaimima_xinmima.Text != textBox_xiugaimima_querenmima.Text)
            {
                MessageBox.Show("请确认您的两次密码都一致！");
                return;
            }
            string sql = string.Format("update Yonghu set Mima='{0}' where Email='{1}'", textBox_xiugaimima_xinmima.Text, textBox_wangjimima_email.Text);
            DBHelper.ExecuteNonQuery(sql);
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_xiugaimima.Left = 492;
            panel_xiugaimima.Top = 12;
            panel_wangjimima.Left = 492;
            panel_wangjimima.Top = 12;
            panel_xiugaimima.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_xiugaimima_xinmima.TabStop = false;
            textBox_xiugaimima_querenmima.TabStop = false;
            textBox_wangjimima_email.Text = "";
            textBox_wangjimima_yanzhengma.Text = "";
            textBox_xiugaimima_xinmima.Text = "";
            textBox_xiugaimima_querenmima.Text = "";
            Yonghu.zhanghao = "";
            Yonghu.mima = "";
            Yonghu.shenfen = "";
            Yonghu.name = "";
            Yonghu.xingbie = "";
            Yonghu.shengri = "";
            Yonghu.diqu = "";
            Yonghu.email = "";
            Yonghu.jianjie = "";
        }

        private void button_xiugaimima_denglu_Click(object sender, EventArgs e)
        {
            //修改密码 登录
            if (textBox_xiugaimima_xinmima.Text != textBox_xiugaimima_querenmima.Text)
            {
                MessageBox.Show("请确认您的两次密码都一致！");
                return;
            }
            string sql = string.Format("update Yonghu set Mima='{0}' where Email='{1}'", textBox_xiugaimima_xinmima.Text, textBox_wangjimima_email.Text);
            DBHelper.ExecuteNonQuery(sql);
            Yonghu.mima = textBox_xiugaimima_xinmima.Text;
            //登录按钮 查询数据
            sql = string.Format("select y.Zhanghao,y.Mima,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Email='{0}'", textBox_zhucezhanghao_email.Text);
            DataTable dt = DBHelper.GetDataTable(sql);
            //登录按钮 成功登录 备份用户数据
            Yonghu.zhanghao = dt.Rows[0][0].ToString();
            Yonghu.mima = dt.Rows[0][1].ToString();
            Yonghu.shenfen = dt.Rows[0][2].ToString();
            Yonghu.name = dt.Rows[0][3].ToString();
            Yonghu.xingbie = dt.Rows[0][4].ToString();
            Yonghu.shengri = dt.Rows[0][5].ToString().Substring(0, dt.Rows[0][5].ToString().IndexOf(' '));
            Yonghu.diqu = dt.Rows[0][6].ToString();
            Yonghu.jianjie = dt.Rows[0][7].ToString();
            Yonghu.email = dt.Rows[0][8].ToString();
            //登录按钮 成功登录 离开登录窗体
            Exit.exit = false;
            this.Close();
        }

        private void button_zhucexinxi_quxiao_Click(object sender, EventArgs e)
        {
            //注册信息 取消
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_zhucexinxi.Left = 492;
            panel_zhucexinxi.Top = 12;
            panel_zhucezhanghao.Left = 492;
            panel_zhucezhanghao.Top = 12;
            panel_zhucexinxi.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_zhucexinxi_name.TabStop = false;
            comboBox_zhucexinxi_xingbie.TabStop = false;
            comboBox_zhucexinxi_shengri_nian.TabStop = false;
            comboBox_zhucexinxi_shengri_yue.TabStop = false;
            comboBox_zhucexinxi_diqu.TabStop = false;
            textBox_zhucezhanghao_email.Text = "";
            textBox_zhucezhanghao_yanzhengma.Text = "";
            textBox_zhucexinxi_name.Text = "";
            comboBox_zhucexinxi_xingbie.Text = "";
            comboBox_zhucexinxi_shengri_nian.Text = "";
            comboBox_zhucexinxi_shengri_yue.Text = "";
            comboBox_zhucexinxi_diqu.Text = "";
        }

        private void button_shurumima_quxiao_Click(object sender, EventArgs e)
        {
            //输入密码 取消
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_shurumima.Left = 492;
            panel_shurumima.Top = 12;
            panel_zhucexinxi.Left = 492;
            panel_zhucexinxi.Top = 12;
            panel_zhucezhanghao.Left = 492;
            panel_zhucezhanghao.Top = 12;
            panel_shurumima.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_shurumima_mima.TabStop = false;
            textBox_shurumima_querenmima.TabStop = false;
            textBox_zhucezhanghao_email.Text = "";
            textBox_zhucezhanghao_yanzhengma.Text = "";
            textBox_zhucexinxi_name.Text = "";
            comboBox_zhucexinxi_xingbie.Text = "";
            comboBox_zhucexinxi_shengri_nian.Text = "";
            comboBox_zhucexinxi_shengri_yue.Text = "";
            comboBox_zhucexinxi_diqu.Text = "";
            textBox_shurumima_mima.Text = "";
            textBox_shurumima_querenmima.Text = "";
            //输入密码 删除账号
            string sql = string.Format("detele Yonghu where Email='{0}'", textBox_zhucezhanghao_email.Text);
            if (!DBHelper.ExecuteNonQuery(sql))
            {
                MessageBox.Show("您的默认密码为 ruoxian");
            }
        }

        private void button_zhucezhanghao_queding_Click(object sender, EventArgs e)
        {
            //注册账号 确定
            if (textBox_zhucezhanghao_email.Text == "")
            {
                MessageBox.Show("您还未输入电子邮箱地址！");
                return;
            }
            else if (textBox_zhucezhanghao_yanzhengma.Text == "")
            {
                MessageBox.Show("您还未输入验证码！");
                return;
            }
            string sql = string.Format("select count(*) from Yonghu where Email='{0}'", textBox_wangjimima_email.Text);
            DataTable dt = DBHelper.GetDataTable(sql);
            if (dt.Rows[0][0].ToString() == "0")
            {
                if(textBox_zhucezhanghao_yanzhengma.Text == Yanzhengma.yanzhengma)
                {
                    panel_zhucexinxi.Left = 12;
                    panel_zhucexinxi.Top = 12;
                    panel_zhucexinxi.BringToFront();
                    panel_zhucexinxi.Enabled = true;
                    panel_zhucezhanghao.Enabled = false;
                    textBox_zhucexinxi_name.TabStop = true;
                    comboBox_zhucexinxi_xingbie.TabStop = true;
                    comboBox_zhucexinxi_shengri_nian.TabStop = true;
                    comboBox_zhucexinxi_shengri_yue.TabStop = true;
                    comboBox_zhucexinxi_diqu.TabStop = true;
                    textBox_zhucezhanghao_email.TabStop = false;
                    textBox_zhucezhanghao_yanzhengma.TabStop = false;
                    //注册信息 性别 下拉框绑定数据
                    sql = "select * from Xingbie where XingbieID!=0";
                    DataSet ds = DBHelper.GetDataSet(sql);
                    comboBox_zhucexinxi_xingbie.DataSource = ds.Tables[0];
                    comboBox_zhucexinxi_xingbie.ValueMember = "Xingbie";
                    comboBox_zhucexinxi_xingbie.DisplayMember = "Xingbie";
                    comboBox_zhucexinxi_xingbie.SelectedIndex = -1;
                    //注册信息 生日 年 下拉框绑定数据
                    comboBox_zhucexinxi_shengri_nian.Items.Clear();
                    for (int i = DateTime.Now.Year; i >= DateTime.Now.Year - 100; i--)
                    {
                        comboBox_zhucexinxi_shengri_nian.Items.Add(i);
                    }
                    //注册信息 生日 日 下拉框绑定数据
                    comboBox_zhucexinxi_shengri_ri.Items.Add("—");
                    //注册信息 地区 下拉框绑定数据
                    sql = "select * from Diqu where DiquID!=0";
                    ds = DBHelper.GetDataSet(sql);
                    comboBox_zhucexinxi_diqu.DataSource = ds.Tables[0];
                    comboBox_zhucexinxi_diqu.ValueMember = "Diqu";
                    comboBox_zhucexinxi_diqu.DisplayMember = "Diqu";
                    comboBox_zhucexinxi_diqu.SelectedIndex = -1;
                }
            }
            else
            {
                MessageBox.Show("此邮箱已注册账号！");
                return;
            }
        }

        private void button_zhucezhanghao_huoquyanzhengma_Click(object sender, EventArgs e)
        {
            //注册账号 获取密码
            if (textBox_zhucezhanghao_email.Text == "")
            {
                MessageBox.Show("您还未输入电子邮箱地址！");
                return;
            }
            string sql = string.Format("select count(*) from Yonghu where Email='{0}'", textBox_zhucezhanghao_email.Text);
            DataTable dt = DBHelper.GetDataTable(sql);
            if (dt.Rows[0][0].ToString() != "0")
            {
                MessageBox.Show("此邮箱已注册账号！");
            }
            else
            {
                Yanzhengma.yanzhengma = Email.email(textBox_zhucezhanghao_email.Text);
            }
        }

        private void button_zhucexinxi_queding_Click(object sender, EventArgs e)
        {
            //注册信息 确认
            if (textBox_zhucexinxi_name.Text == "")
            {
                MessageBox.Show("您还未输入昵称！");
            }
            else if (comboBox_zhucexinxi_xingbie.Text == "")
            {
                MessageBox.Show("您还未选择性别！");
            }
            else if (comboBox_zhucexinxi_shengri_nian.Text == "" || comboBox_zhucexinxi_shengri_yue.Text == "" || comboBox_zhucexinxi_shengri_ri.Text == "")
            {
                MessageBox.Show("您还未选择生日！");
            }
            else if (comboBox_zhucexinxi_diqu.Text == "")
            {
                MessageBox.Show("您还未选择地区！");
            }
            else
            {
                //创建账号
                string shengri = comboBox_zhucexinxi_shengri_nian.Text + "-" + comboBox_zhucexinxi_shengri_yue.Text + "-" + comboBox_zhucexinxi_shengri_ri.Text;
                string sql = string.Format("select count(*) from Yonghu");
                DataTable dt = DBHelper.GetDataTable(sql);
                double zhanghao = double.Parse(dt.Rows[0][0].ToString()) + 1000000000 + 1;
                for (; zhanghao > 0; zhanghao--)
                {
                    sql = string.Format("select count(*) from Yonghu where Zhanghao='{0}'", Convert.ToString(zhanghao));
                    dt = DBHelper.GetDataTable(sql);
                    if (dt.Rows[0][0].ToString() == "0")
                    {
                        sql = string.Format("insert Yonghu(Zhanghao,Name,Xingbie,Shengri,Diqu,Email) select '{0}','{1}',(select XingbieID from Xingbie where Xingbie='{2}'),'{3}',(select DiquID from Diqu where Diqu='{4}'),'{5}'", Convert.ToString(zhanghao), textBox_zhucexinxi_name.Text, comboBox_zhucexinxi_xingbie.Text, shengri, comboBox_zhucexinxi_diqu.Text, textBox_zhucezhanghao_email.Text);
                        DBHelper.ExecuteNonQuery(sql);
                        break;
                    }
                }
                zhanghao_zhuce.Text = Convert.ToString(zhanghao);
                //打开输入密码页面
                panel_shurumima.Left = 12;
                panel_shurumima.Top = 12;
                panel_shurumima.BringToFront();
                panel_shurumima.Enabled = true;
                panel_zhucexinxi.Enabled = false;
                textBox_shurumima_mima.TabStop = true;
                textBox_shurumima_querenmima.TabStop = true;
                textBox_zhucexinxi_name.TabStop = false;
                comboBox_zhucexinxi_xingbie.TabStop = false;
                comboBox_zhucexinxi_shengri_nian.TabStop = false;
                comboBox_zhucexinxi_shengri_yue.TabStop = false;
                comboBox_zhucexinxi_diqu.TabStop = false;
            }
        }

        private void comboBox_zhucexinxi_shengri_yue_SelectedIndexChanged(object sender, EventArgs e)
        {
            //注册信息 生日 日 下拉框绑定数据
            comboBox_zhucexinxi_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_zhucexinxi_shengri_yue.Text == "1" || comboBox_zhucexinxi_shengri_yue.Text == "3" || comboBox_zhucexinxi_shengri_yue.Text == "5" || comboBox_zhucexinxi_shengri_yue.Text == "7" || comboBox_zhucexinxi_shengri_yue.Text == "8" || comboBox_zhucexinxi_shengri_yue.Text == "10" || comboBox_zhucexinxi_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_zhucexinxi_shengri_yue.Text == "4" || comboBox_zhucexinxi_shengri_yue.Text == "6" || comboBox_zhucexinxi_shengri_yue.Text == "9" || comboBox_zhucexinxi_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_zhucexinxi_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_zhucexinxi_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_zhucexinxi_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_zhucexinxi_shengri_ri.Items.Add(i);
            }
        }

        private void comboBox_zhucexinxi_shengri_nian_SelectedIndexChanged(object sender, EventArgs e)
        {
            //注册信息 生日 日 下拉框绑定数据
            comboBox_zhucexinxi_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_zhucexinxi_shengri_yue.Text == "1" || comboBox_zhucexinxi_shengri_yue.Text == "3" || comboBox_zhucexinxi_shengri_yue.Text == "5" || comboBox_zhucexinxi_shengri_yue.Text == "7" || comboBox_zhucexinxi_shengri_yue.Text == "8" || comboBox_zhucexinxi_shengri_yue.Text == "10" || comboBox_zhucexinxi_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_zhucexinxi_shengri_yue.Text == "4" || comboBox_zhucexinxi_shengri_yue.Text == "6" || comboBox_zhucexinxi_shengri_yue.Text == "9" || comboBox_zhucexinxi_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_zhucexinxi_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_zhucexinxi_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_zhucexinxi_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_zhucexinxi_shengri_ri.Items.Add(i);
            }
        }

        private void button_shurumima_queding_Click(object sender, EventArgs e)
        {
            //输入密码 确定
            if (textBox_shurumima_mima.Text == "" || textBox_shurumima_querenmima.Text == "")
            {
                MessageBox.Show("请输入您的密码！");
                return;
            }
            if (textBox_shurumima_mima.Text != textBox_shurumima_querenmima.Text)
            {
                MessageBox.Show("请确认您的两次密码都一致！");
                return;
            }
            string sql = string.Format("update Yonghu set Mima='{0}' where Email='{1}'", textBox_shurumima_mima.Text, textBox_zhucezhanghao_email.Text);
            if (!DBHelper.ExecuteNonQuery(sql))
            {
                MessageBox.Show("密码上传失败！您的默认密码为 ruoxian");
            }
            //显示主页面
            this.Text = "若闲Ruoxian-Novel    账号登录";
            panel_shurumima.Left = 492;
            panel_shurumima.Top = 12;
            panel_zhucexinxi.Left = 492;
            panel_zhucexinxi.Top = 12;
            panel_zhucezhanghao.Left = 492;
            panel_zhucezhanghao.Top = 12;
            panel_shurumima.Enabled = false;
            textBox_zhanghao.Enabled = true;
            textBox_mima.Enabled = true;
            checkBox_jizhumima.Enabled = true;
            button_wangjimima.Enabled = true;
            button_zhucezhanghao.Enabled = true;
            textBox_zhanghao.TabStop = true;
            textBox_mima.TabStop = true;
            textBox_shurumima_mima.TabStop = false;
            textBox_shurumima_querenmima.TabStop = false;
            textBox_zhucezhanghao_email.Text = "";
            textBox_zhucezhanghao_yanzhengma.Text = "";
            textBox_zhucexinxi_name.Text = "";
            comboBox_zhucexinxi_xingbie.Text = "";
            comboBox_zhucexinxi_shengri_nian.Text = "";
            comboBox_zhucexinxi_shengri_yue.Text = "";
            comboBox_zhucexinxi_diqu.Text = "";
            textBox_shurumima_mima.Text = "";
            textBox_shurumima_querenmima.Text = "";
        }

        private void button_shurumima_denglu_Click(object sender, EventArgs e)
        {
            //输入密码 登录
            if (textBox_shurumima_mima.Text==""|| textBox_shurumima_querenmima.Text=="")
            {
                MessageBox.Show("请输入您的密码！");
                return;
            }
            if (textBox_shurumima_mima.Text != textBox_shurumima_querenmima.Text)
            {
                MessageBox.Show("请确认您的两次密码都一致！");
                return;
            }
            string sql = string.Format("update Yonghu set Mima='{0}' where Email='{1}'", textBox_shurumima_mima.Text, textBox_zhucezhanghao_email.Text);
            if (!DBHelper.ExecuteNonQuery(sql))
            {
                MessageBox.Show("密码上传失败！您的默认密码为 ruoxian");
            }
            //登录主窗体
            try
            {
                //登录按钮 查询数据
                sql = string.Format("select y.Zhanghao,y.Mima,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Email='{0}'", textBox_zhucezhanghao_email.Text);
                DataTable dt = DBHelper.GetDataTable(sql);
                //登录按钮 成功登录 备份用户数据
                Yonghu.zhanghao = dt.Rows[0][0].ToString();
                Yonghu.mima = dt.Rows[0][1].ToString();
                Yonghu.shenfen = dt.Rows[0][2].ToString();
                Yonghu.name = dt.Rows[0][3].ToString();
                Yonghu.xingbie = dt.Rows[0][4].ToString();
                Yonghu.shengri = dt.Rows[0][5].ToString().Substring(0, dt.Rows[0][5].ToString().IndexOf(' '));
                Yonghu.diqu = dt.Rows[0][6].ToString();
                Yonghu.jianjie = dt.Rows[0][7].ToString();
                Yonghu.email = dt.Rows[0][8].ToString();
                //登录按钮 成功登录 离开登录窗体
                Exit.exit = false;
                this.Close();
            }
            catch
            {
                //登录按钮 登录失败 此账号不存在
                MessageBox.Show("登录失败！");
            }
        }
    }
}
